package com.hebeu.gfh.service.impl;

import com.hebeu.gfh.mapper.ClubsMapper;
import com.hebeu.gfh.mapper.UserMapper;
import com.hebeu.gfh.pojo.po.ClubApplication;
import com.hebeu.gfh.pojo.po.Clubs;
import com.hebeu.gfh.pojo.po.RecuritNew;
import com.hebeu.gfh.pojo.vo.IdAndName;
import com.hebeu.gfh.pojo.vo.clubidAndname;
import com.hebeu.gfh.pojo.vo.pages;
import com.hebeu.gfh.service.clubsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 刘剑利
 * @Version: v1.0
 */
@Service("clubsService")
public class clubsServiceImpl implements clubsService {
    @Autowired
    ClubsMapper clubsMapper;

    @Autowired
    UserMapper userMapper;
    @Override
    public void addClub(Clubs clubs) {
        clubsMapper.addClub(clubs);
    }

    @Override
    public void updateClub(Clubs clubs) {
        clubsMapper.updateClub(clubs);
    }

    @Override
    public void deleteClub(int clubId) {
        clubsMapper.deleteClub(clubId);
    }

    @Override
    public List<Clubs> findAllClub(pages page) {
        int a =page.getPage();
        page.setPage((a - 1) * page.getPagesize());
        List<Clubs> clubsList = clubsMapper.findAllClub(page);
        return clubsList;
    }

    @Override
    public Clubs findClubByclubId(int clubId) {
        Clubs club = clubsMapper.findClubByclubId(clubId);
        return club;
    }

    @Override
    public List<Clubs> findClubsByclubName(String clubName) {
        List<Clubs> clubsList = clubsMapper.findClubsByclubName(clubName);
        return clubsList;
    }

    @Override
    public int findClubCount() {
        int count = clubsMapper.findClubCount();
        return count;
    }

    @Override
    public List<Clubs> findClubByclubTid(int clubTid) {
        List<Clubs> clubsList = clubsMapper.findClubByclubTid(clubTid);
        return clubsList;
    }

    @Override
    public RecuritNew findClubnewByclubId(int clubId) {
        RecuritNew recuritNew =clubsMapper.findClubnewByclubId(clubId);
        return recuritNew;
    }

    @Override
    public List<Clubs> findrecuritingnew(pages pages) {
        List<Clubs> clubsList = clubsMapper.findrecuritingnew(pages);
        return clubsList;
    }

    @Override
    public int findrecuritingnewNum() {
        int num = clubsMapper.findrecuritingnewNum();
        return num;
    }

    @Override
    public List<clubidAndname> findIsManagerClubIdAndName(int userId) {
        List<clubidAndname> clubidAndnameList = clubsMapper.findIsManagerClubIdAndName(userId);
        return clubidAndnameList;
    }

    @Override
    public void addRecuritNew(RecuritNew recuritNew) {
        clubsMapper.recuritNew(recuritNew);
    }

    @Override
    public void updateRecuritNew(RecuritNew recuritNew) {
        clubsMapper.updateRecuritNew(recuritNew);
    }

    @Override
    public void deleteRecuritNew(int clubId) {
        clubsMapper.deleteRecuritNew(clubId);
    }

    @Override
    public List<Clubs> clubrecommend() {
        List<Clubs> clubsList =clubsMapper.clubrecommend();
        return clubsList;
    }

    @Override
    public String getClubNameById(int clubId) {
        String clubName = clubsMapper.getClubNameById(clubId);
        return clubName;
    }

    @Override
    public List<ClubApplication> getApplicationByUserId(IdAndName idAndName) {
        int uid;
        try {
         uid = userMapper.findUserIdByUserName(idAndName.getUserName() );
        }catch (Exception e){
           uid =0;
            List<ClubApplication> clubApplicationList = clubsMapper.getApplicationByUserId(idAndName.getUserId(),uid);
            return clubApplicationList;
        }
        List<ClubApplication> clubApplicationList = clubsMapper.getApplicationByUserId(idAndName.getUserId(),uid);
        return clubApplicationList;
    }


}
